/*
 *所有关于Bak_partout_117类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Bak_partout_117Service对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MyErp.IRepositories;
using System.Collections.Generic;
using System;
using VOL.Core.DBManager;

namespace MyErp.Services
{
    public partial class Bak_partout_117Service
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IBak_partout_117Repository _repository;//访问数据库
        WebResponseContent webResponse = new WebResponseContent();
        [ActivatorUtilitiesConstructor]
        public Bak_partout_117Service(
            IBak_partout_117Repository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }
        public override WebResponseContent Update(SaveModel saveModel)
        {
            //sqlerver dblink到oracle执行update时需要用到openquery否则效率会非常慢，修改查询都是用openquery，可以提示运行效率
            //下面的实例绕开SQLServer事务，直接执行openquery的update的SQL语句
            UpdateOnExecuting = (Bak_partout_117 order, object addList, object updateList, List<object> delKeys) =>
            {
                Console.WriteLine(order.BAK_SCM_SAP_PARTOUT_ID);
                decimal ls_id= order.BAK_SCM_SAP_PARTOUT_ID;
                string pflag = order.PFLAG;
                string TPLANT_NO = order.TPLANT_NO;
                string OUTBOUND_TYPE=order.OUTBOUND_TYPE;
                DBServerProvider.SqlDapper.ExcuteNonQuery("UPDATE OPENQUERY([117],'SELECT pflag,TPLANT_NO,OUTBOUND_TYPE FROM BAK_SCM_SAP_PARTOUT WHERE bak_scm_sap_partout_id=" + ls_id + "') SET pflag=@pflag, TPLANT_NO=@TPLANT_NO,OUTBOUND_TYPE=@OUTBOUND_TYPE", new { pflag, TPLANT_NO, OUTBOUND_TYPE });
                //_repository.Update(order,true);
                webResponse.Code = "-1";//-1表示不执行后面的update，测试强制返回
                //webResponse.Message = "";
                return webResponse.OK("修改成功！");
            };
            return base.Update(saveModel);
        }
        public override PageGridData<Bak_partout_117> GetPageData(PageDataOptions options)
        {

           // QuerySql = $@"select * from SellOrder ";
            return base.GetPageData(options);
        }
    }
}
